package generator;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class codeGenertor {
    public static void main(String[] args) {
        String auth="student";
        String username="gxh";
        String password="147258gxh@";
        String url="jdbc:mysql://rm-bp1p0yg75w0tacub67o.mysql.rds.aliyuncs.com:3306/music?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC";
        String driverName="com.mysql.cj.jdbc.Driver";
        String packages="com.qst.domain";
        String table="menu";
        String model="domain";

        AutoGenerator autoGenerator=new AutoGenerator();
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(System.getProperty("user.dir") + "/"+model+"/src/main/java");
        globalConfig.setAuthor(auth);
        globalConfig.setOpen(false);
        globalConfig.setServiceName("%sService");
        globalConfig.setSwagger2(true);
        autoGenerator.setGlobalConfig(globalConfig);
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl(url);
        dataSourceConfig.setDriverName(driverName);
        dataSourceConfig.setUsername(username);
        dataSourceConfig.setPassword(password);
        autoGenerator.setDataSource(dataSourceConfig);
        PackageConfig packageConfig=new PackageConfig();
        packageConfig.setModuleName(null);
        packageConfig.setController("controller");
        packageConfig.setService("service");
        packageConfig.setEntity("entity");
        packageConfig.setMapper("mapper");
        packageConfig.setParent(packages);
        autoGenerator.setPackageInfo(packageConfig);
        StrategyConfig strategyConfig=new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setTablePrefix(packageConfig.getModuleName()+"_");
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setEntityLombokModel(true);
        strategyConfig.setRestControllerStyle(true);
        strategyConfig.setControllerMappingHyphenStyle(true);
        strategyConfig.setInclude(table);
        autoGenerator.setStrategy(strategyConfig);
        autoGenerator.execute();
    }
}
